﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for TransposeDataTable
/// </summary>
public class ConvertSubFigures
{
  public ConvertSubFigures()
  {

  }

  public static DataTable Convert(DataTable dataTable)
  {
    DataTable newDataTable = new DataTable();
    newDataTable.Columns.Add(" ");
    //Get all the rows and change into columns
    for (int row = 0; row < dataTable.Rows.Count; row++)
    {
      newDataTable.Columns.Add(dataTable.Rows[row][0].ToString()); //Add column titles
    }

    DataRow dr;
    //get all the columns and make it as rows
    for (int column = 1; column < dataTable.Columns.Count; column++)
    {
      dr = newDataTable.NewRow();
      string keyfigureName = dataTable.Columns[column].ToString();

      switch (keyfigureName)  //Need to put "Indeks" in front of revenue, gross margin and result
      {
        case "revenue":
        case "gross_margin":
        case "result":
          dr[0] = "Indeks " + Dictionary.Translate(keyfigureName).ToLower();
          break;
        default:
          dr[0] = Dictionary.Translate(keyfigureName);
          break;
      }

      for (int row = 1; row <= dataTable.Rows.Count; row++)
      {
        dr[row] = ConvertKeyFigureDigit.Convert(dataTable.Rows[row - 1][column].ToString(), keyfigureName);
      }
      newDataTable.Rows.Add(dr);
    }
    return newDataTable;
  }
}